package com.zzyl.nursing.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.zzyl.nursing.domain.TableDataInfo;
import com.zzyl.nursing.domain.WechatData;
import com.zzyl.nursing.dto.NursingWechatPageQueryDTO;
import com.zzyl.nursing.mapper.NursingWechatMapper;
import com.zzyl.nursing.service.INursingWechatService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NursingWechatServiceImpl implements INursingWechatService {

@Autowired
private NursingWechatMapper nursingWechatMapper;
    @Override
    public TableDataInfo page(NursingWechatPageQueryDTO nursingWechatPageQueryDTO) {
        Page<WechatData> page = new Page<>(nursingWechatPageQueryDTO.getPageNum(),  nursingWechatPageQueryDTO.getPageSize());
        QueryWrapper<WechatData> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNoneBlank(nursingWechatPageQueryDTO.getName()),"name",nursingWechatPageQueryDTO.getName());
        queryWrapper.eq(nursingWechatPageQueryDTO.getStatus() != null,"status",nursingWechatPageQueryDTO.getStatus());
        queryWrapper.orderByAsc("order_no");
        Page<WechatData> resultPage = nursingWechatMapper.selectPage(page, queryWrapper);
        return TableDataInfo.success(resultPage.getTotal(),resultPage.getRecords());

    }

    @Override
    public WechatData getById(Long id) {
        WechatData wechatData = nursingWechatMapper.selectById(id);
        return wechatData;
    }
}
